home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / BoundedFifo.cc < prev    next >
C/C++ Source or Header  |  1990-07-09  |  2KB  |  81 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. // Copyright (C) 1989 University of Colorado, Boulder, Colorado
  5. // Copyright (C) 1990 University of Colorado, Boulder, Colorado
  6. //
  7. // written by Dirk Grunwald (grunwald@foobar.colorado.edu)
  8. //
  9. #include "BoundedFifo.h"
  10. #include "stream.h"
  11. #include "assert.h"
  12.  
  13. BoundedFifo::BoundedFifo(int xpMaxLength, int defaultLength)
  14.     : (defaultLength),
  15.     upperBoundLock(xpMaxLength, &upperBoundLockFifo), upperBoundLockFifo()
  16. {
  17.     pMaxLength = xpMaxLength;
  18. };
  19.  
  20. void
  21. BoundedFifo::add(AwesimeFifoItem* t) {
  22.     upperBoundLock.reserve();
  23.     LockedFifo::add(t);
  24.     lowerBoundLock.release();
  25. }
  26.  
  27. bool
  28. BoundedFifo::remove(AwesimeFifoItem *item)
  29. {
  30.     (void) lowerBoundLock.reserve();
  31.     bool ok = LockedFifo::remove(item);
  32.     assert(ok);
  33.     upperBoundLock.release();
  34.     return(ok);
  35. }
  36.  
  37. bool
  38. BoundedFifo::removeNoBlock(AwesimeFifoItem *item)
  39. {
  40.     bool ok = removeNoBlock( item );
  41.     if (ok) {
  42.     upperBoundLock.release();
  43.     }
  44.     return(ok);
  45. }
  46.  
  47. bool BoundedFifo::removeIfFound(AwesimeFifoItem *item) {
  48.     (void) lowerBoundLock.reserve();
  49.     bool ok = LockedFifo::removeIfFound(item);
  50.     if (ok) {
  51.     upperBoundLock.release();
  52.     } else {
  53.     lowerBoundLock.release();
  54.     }
  55.     return(ok);
  56. }
  57.  
  58. bool
  59. BoundedFifo::doDelete(AwesimeFifoIndex& index) {
  60.     //
  61.     // This is problematic. Since this is a LockedFifo, this person
  62.     // will be the only one with access to the list. If he blocks
  63.     // at this point, he's dead-meat.
  64.     //
  65.     // So, is this an error? If so, should we protect him?
  66.     //
  67.     bool whaHap = AwesimeFifo::doDelete(index);
  68.     if (whaHap) {
  69.     bool noBlock = lowerBoundLock.reserveNoBlock();
  70.     assert( noBlock );
  71.     lowerBoundLock.reserve();
  72.     upperBoundLock.release();
  73.     }
  74.     return(whaHap);
  75. }
  76.  
  77. unsigned int BoundedFifo::size()
  78. {
  79.     return(AwesimeFifo::size());
  80. }
  81.